﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System.Runtime.Serialization;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using BrainTechLLC.ThreadSafeObjects;
using BrainTechLLC;
using System.Reflection;

namespace BrainTechLLC
{
    public static class TypeProvider_RegisterTypes
    {
        public static Type[] RegisterTypes()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            DLLContents contents = TypeProvider.GetInstance().GetDLLContents(assembly.FullName);
            var types = assembly.GetTypes();
            types.ForEach(type =>
            {
                if (type.IsTypeOkay())
                    TypeProvider.GetInstance().AddType(contents, type);
            });
            return types;
        }
    }

    /// <summary>
    /// Stores information about the contents of a loaded assembly / DLL
    /// </summary>
    [Serializable]
#if NO_SILVERLIGHT
    [Browsable(true)]
    [TypeConverter(typeof(ExpandableObjectConverter))]
#endif
    public class DLLContents
    {
        private ThreadSafeLookup<Type, TypeDescription> _typesInDLL = new ThreadSafeLookup<Type, TypeDescription>();

        public string DLLName { get; set; }

        public ThreadSafeLookup<Type, TypeDescription> TypesInDLL
        {
            get { return _typesInDLL; }
            set { _typesInDLL = value; }
        }
    }
}
